<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>销售报表</title>
  </head>
  <body>
    <div id="reports_search_form" style="height:580px;" class="x-form-item">
    </div>
    <script>
        /*
         * Ext JS Library 2.1
         * Copyright(c) 2006-2008, Ext JS, LLC.
         * licensing@extjs.com
         *
         * http://extjs.com/license
         */
        Ext.onReady(function(){
            var searchAirways = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getInternalAirways'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root',
                        id: 'id'
                    }, ['airways_code', 'airways_name'])
                }),
                name: 'search_airways',
                loadingText: '正在加载...',
                displayField: 'airways_name',
                valueField: 'airways_code',
                mode: 'remote',
                triggerAction: 'all',
                hiddenName: 'airwayscode',
                fieldLabel: "航空公司",
                emptyText: '请选择...',
                editable: false,
                //allowBlank: false,
                width: 90,
                maxHeight: 150,
                tabIndex: 4
            });
            var radioTime = new Ext.form.Radio({
                fieldLabel: '航程类型',
                name: 'search_type',
                id: 'search_type_0',
                boxLabel: '仅按时间',
                checked: true,
                hideLabel: true,
                inputValue: 'time'
            });
            var radioAirways = new Ext.form.Radio({
                fieldLabel: '返程',
                name: 'search_type',
                id: 'search_type_1',
                boxLabel: '按航空公司',
                checked: false,
                hideLabel: true,
                inputValue: 'airways'
            });
            var radioFromTo = new Ext.form.Radio({
                fieldLabel: '返程',
                name: 'search_type',
                id: 'search_type_2',
                boxLabel: '按航段',
                checked: false,
                hideLabel: true,
                inputValue: 'fromto'
            });
            var searchDateBegin = new Ext.form.DateField({
                fieldLabel: '<span class="red">*</span>开始日期',
                name: 'search_date_begin',
                id: 'search_date_begin',
                format: 'Y-m-d', //格式化日期   
                width: '80',
                //disabledDays: [0,6],	//不让选择周六，周日   
                //disabledDaysText: "周末要休息",   
                invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                allowBlank: false,
                inputType: '2008-01-01',
                anchor: '90%',
                vtype: 'daterange',
                endDateField: 'search_date_end'
            });
            
            var searchDateEnd = new Ext.form.DateField({
                fieldLabel: '<span class="red">*</span>结束日期',
                name: 'search_date_end',
                id: 'search_date_end',
                format: 'Y-m-d', //格式化日期   
                width: '80',
                //disabledDays: [0,6],	//不让选择周六，周日   
                //disabledDaysText: "周末要休息",   
                invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                allowBlank: false,
                inputType: '2008-01-01',
                anchor: '90%',
                vtype: 'daterange',
                startDateField: 'search_date_begin'
            });
            
            var fromAirport = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getAllAirportComboBox'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root',
                        id: 'id'
                    }, ['airport_code', 'airport_name'])
                }),
                name: 'from_airport',
                loadingText: '正在加载...',
                displayField: 'airport_name',
                valueField: 'airport_code',
                mode: 'remote',
                triggerAction: 'all',
                hiddenName: 'from_airport_code',
                fieldLabel: "始发城市",
                emptyText: '请选择...',
                editable: false,
                //allowBlank: false,
                width: 150,
                maxHeight: 150,
                tabIndex: 4
            });
            
            var toAirport = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getAllAirportComboBox'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root',
                        id: 'id'
                    }, ['airport_code', 'airport_name'])
                }),
                name: 'to_airport',
                loadingText: '正在加载...',
                displayField: 'airport_name',
                valueField: 'airport_code',
                mode: 'remote',
                triggerAction: 'all',
                hiddenName: 'to_airport_code',
                fieldLabel: "目的城市",
                emptyText: '请选择...',
                editable: false,
                //allowBlank: false,
                width: 150,
                maxHeight: 150,
                tabIndex: 4
            });
           
                
            var searchFormPanel = new Ext.form.FormPanel({
                //baseCls: 'x-plain',
                labelWidth: 70,
                width: '600',
                labelAlign: 'right',
                frame : true,
                url: '/reports/createSalesReport',
                //defaultType: 'textfield',
                items: [{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .2,
                                layout: 'form',
                                border: false,
                                items: [radioTime]
                            }, {
                                columnWidth: .4,
                                layout: 'form',
                                border: false,
                                items: [searchDateBegin]
                            }, {
                                columnWidth: .4,
                                layout: 'form',
                                border: false,
                                items: [searchDateEnd]
                            }]
                    },{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .2,
                                layout: 'form',
                                border: false,
                                items: [radioFromTo]
                            }, {
                                columnWidth: .4,
                                layout: 'form',
                                border: false,
                                items: [fromAirport]
                            }, {
                                columnWidth: .4,
                                layout: 'form',
                                border: false,
                                items: [toAirport]
                            }]
                    },{
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .2,
                                layout: 'form',
                                border: false,
                                items: [radioAirways]
                            }, {
                                columnWidth: .8,
                                layout: 'form',
                                border: false,
                                items: [searchAirways]
                            }]
                    }],
                buttons: [{
                        text: '生成报表',
                        handler: function(){
                            // check form value 
                            if (searchFormPanel.form.isValid()) {
                                searchFormPanel.form.submit({
                                    method: 'GET',
                                    success: function(result, response){
                                        if (response.result.info == "报表成功") {
                                            Ext.MessageBox.alert('报表下载', response.result.path);
                                        }
                                        else {
                                            Ext.MessageBox.alert('消息', result.responseText);
                                        }
                                    },
                                    failure: function(result, response){
                                        Ext.MessageBox.alert('提示', '生成销售报表时通信错误!');
                                    }
                                });
                            }
                            else {
                                Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                            }
                        }
                    }]
            });
            searchFormPanel.render('reports_search_form');
        });
    </script>
  </body>
</html>
